﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR43Request", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR43Request))]
    public class RR43RequestSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR43Request clazz;
        
        public RR43RequestSerializer(IRR43Request clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("DokumendiTyyp");
            if (clazz.DokumendiTyyp!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "dokumendi_tyyp");
                Writer.WriteString(clazz.DokumendiTyyp.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DokumendiTyyp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("DokumendiSeeria");
            if (clazz.DokumendiSeeria!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiSeeria))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DokumendiSeeria");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("DokumendiKood");
            if (clazz.DokumendiKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiKood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DokumendiKood");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="DokumendiTyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR43Request>DokumendiTyyp");
                }
                clazz.DokumendiTyyp = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.DokumendiTyyp(Reader.ReadElementString("DokumendiTyyp"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR43Request>DokumendiTyyp", Reader.LocalName);
            }
            if (Reader.LocalName=="DokumendiSeeria") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR43Request>DokumendiSeeria");
                }
                clazz.DokumendiSeeria = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiSeeria")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR43Request>DokumendiSeeria", Reader.LocalName);
            }
            if (Reader.LocalName=="DokumendiKood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR43Request>DokumendiKood");
                }
                clazz.DokumendiKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiKood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR43Request>DokumendiKood", Reader.LocalName);
            }
        }
    }
}
